from panda3d.core import Point2,Point3,Vec2,Vec3,Vec4
from direct.interval.IntervalGlobal import *
'''
	Andrew Oberlin. Michael Jacobs, Tom Williams
	Date: February 8, 2012

	Platform class for AI and displaying
'''
class Block:
	'''
		Block Constructor for Grouping Blocks
	'''
	def __init__(self, parent):
		self.parent = parent
		self.type = 'BLOCK'
		self.loadModel()
	
	'''
		Loads the block and its texture
	'''
	def loadModel(self):
		self.loadTexture()
		self.set2DProps()
	
	def setOriginalY(self):
		self.originalY = self.model.getY()
		
	'''
		Load the plae and the block texture
	'''
	def loadTexture(self):
		self.model = self.parent.loader.loadModelCopy("models/plane")
		self.texture = self.parent.loader.loadTexture("models/levels/objects/breakable_block.png")
		
	'''
		Sets the properties for a two dimensional figure
	'''
	def set2DProps(self):
		self.model.setHpr(Vec3(0,-90,0))
		self.model.setScale(self.parent.BLOCK_SIZE)
		
		# maximize efficiency
		self.model.setBin("unsorted", 0)
		self.model.setDepthTest(False)
		self.model.setTransparency(1)
		
		self.model.setTexture(self.texture)
		self.model.reparentTo(render)
		
	'''
		Removes the block from the Panda3D render and destroys the block
	'''
	def destroy(self):
		self.model.removeNode()
		
	'''
		Reset's the texture of this to the new texture
	'''
	def resetTexture(self, path):
		self.texture = self.parent.loader.loadTexture(path)
		self.model.setTexture(self.texture)
		
		return self

	'''
		Makes the box jump up and come back down when it is hit
	'''	
	def startCollisionAnimation(self):
		hitSequence = Sequence(
			self.model.posInterval(0.10, 
				Vec3(self.model.getX(), self.originalY + self.parent.BLOCK_SIZE*0.33, 0)
			),
			self.model.posInterval(0.10, 
				Vec3(self.model.getX(), self.originalY, 0)
			)
		)
		
		hitSequence.start()
'''
	Air Block -- A block that has no actual data/filler
'''
class AirBlock(Block):
	'''
		No init items except establishing the parent
	'''
	def __init__(self, parent):
		self.parent = parent
		self.type = 'AIR'

'''
	Question Block -- A block that gives a mushroom when hit
'''
class QuestionBlock(Block):
	'''
		Constructor for the Question Block
	'''
	def __init__(self, parent, item, numItems):
		self.type = 'QUESTION'
		self.parent = parent
		self.item = item
		self.numItems = numItems
		self.loadModel()
		
	'''
		Use the question block texture
	'''
	def loadTexture(self):
		self.model = self.parent.loader.loadModelCopy("models/plane")
		self.texture = self.parent.loader.loadTexture("models/levels/objects/question_block.png")
	


class PipeBlock(Block):
	'''
		Constructor for the Question Block
	'''
	def __init__(self, parent):
		self.type = 'PIPE'
		self.parent = parent
		self.loadModel()
		
	'''
		Use the question block texture
	'''
	def loadTexture(self):
		self.model = self.parent.loader.loadModelCopy("models/plane")
		self.texture = self.parent.loader.loadTexture("models/levels/objects/pipe.png")
			
'''
	Ground Block -- A block that is used for textureing the ground
'''
class GroundBlock(Block):
	'''
		Constructor for the Question Block
	'''
	def __init__(self, parent):
		self.type = 'GROUND'
		self.parent = parent
		self.loadModel()
		
	'''
		Use the ground block texture
	'''
	def loadTexture(self):
		self.model = self.parent.loader.loadModelCopy("models/plane")
		self.texture = self.parent.loader.loadTexture("models/levels/objects/ground_block.png")   
	
	
	
	
	